package com.github.dgxwl;

import java.io.IOException;
import java.util.Arrays;

import com.github.dgxwl.base.ApiGenerator;
import com.github.dgxwl.base.entity.Table;
import com.github.dgxwl.base.handler.db.CreateSQLHandler;

public class ParseCreateTableSQL {

	public static void main(String[] args) {
		String mainTableSql = "CREATE TABLE `t_city` (\r\n" + 
				"  `city_id` int(11) NOT NULL,\r\n" + 
				"  `oname` varchar(255) NOT NULL,\r\n" + 
				"  `fullname` varchar(255) NOT NULL,\r\n" + 
				"  `longitude` double(10,6) DEFAULT NULL,\r\n" + 
				"  `latitude` double(10,6) DEFAULT NULL,\r\n" + 
				"  `parent_id` int(11) NOT NULL,\r\n" + 
				"  PRIMARY KEY (`city_id`)\r\n" + 
				") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='市';";

		Table table = CreateSQLHandler.getTableByCreateSQL(mainTableSql);
		
//		System.out.println(table);
		try {
			new ApiGenerator(Arrays.asList(table), Arrays.asList(table.getTableName().substring(table.getTableName().indexOf('_') + 1))).generate();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
